package com.uikoo9.job;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.uikoo9.manage.y.model.YIdeaModel;
import com.uikoo9.manage.y.util.TimeUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 重复每日，每周定时需要新增的任务等。
 */
public class JobB implements Job {
    static int callTime = 0;

    @Override
    public void execute(JobExecutionContext arg0) throws JobExecutionException {
        String group = arg0.getJobDetail().getKey().getGroup();
        String _table = "select a.* from t_y_idea a , t_y_rela r , t_y_job j\n" +
                "where  r.y_rela_srctable='t_y_idea' and r.y_rela_relatable='t_y_job' \n" +
                " and a.id = r.y_rela_srcid and r.y_rela_relaid = j.id and j.y_job_group = ?  ";
        List<Record> jsouphtmllist = Db.find(_table,group);
        for (Record jsouphtml : jsouphtmllist) {
            jsouphtml.set("id",null);
            jsouphtml.set("y_idea_name",jsouphtml.get("y_idea_name")+ TimeUtil.getCurrentDate("yyyy-MM-dd"));
            YIdeaModel.dao.setAttrs(jsouphtml.getColumns()).save();
        }

        testNetIfList();
        callTime++;
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " JobA works,callTime is: " + callTime);
    }

    public void testNetIfList() {
        try {

            String _table = "select * from t_y_idea";
            List<Record> jsouphtmllist = Db.find(_table);
            for (Record jsouphtml : jsouphtmllist) {
                print("bbb+++++"+jsouphtml.get("id").toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    void print(String msg) {
        System.out.println(msg);
    }

}
